<?php  
class WUser extends ANotify 
{
	var $db;
	var $table_user;
	var	$Field_Name;
	var $Field_Field_Pwd;
	var $md5;
	function WUser(&$db,$table,$Field_Name,$Field_Pwd,$md5=1)
	{
		$this->db= $db;
		$this->table= $table;
		$this->Field_Name= $Field_Name;
		$this->Field_Pwd		= $Field_Pwd;
		$this->md5= $md5;
	}
	function login($Login_Name,$Login_Password)
	{
		$name	= '';
		$pwd	= '';
		if(isset($_POST[$Login_Name]))
		{
			$name = $_POST[$Login_Name];
			if($name == '')
			$this->halt("请输入登陆名！","");
		}
		else $this->halt("请输入登陆名！","");
		if(isset($_POST[$Login_Password]))
		{
			$pwd = $_POST[$Login_Password];
			if($pwd == '')
			$this->halt("请输入登陆密码！","");
		} else $this->halt("请输入登陆密码！","");
		if($this->md5)
		$pwd = md5($pwd);
		$active = date('Y-m-d H:i:s');
		$ip = ip();
		$sql = "select {$this->Field_Pwd},id,realname from {$this->table} where {$this->Field_Name} = '$name'";
		if($query = $this->db->query($sql))
		{
			if($row = mysql_fetch_array($query))
			{
				if($row[$this->Field_Pwd] == $pwd)
				{
					$_SESSION['REEYEE_MANAGE']['user']		= $name;
					$_SESSION['REEYEE_MANAGE']['realname']	= $row["realname"];
					$_SESSION['REEYEE_MANAGE']['pwd']		= $pwd;
					$_SESSION['REEYEE_MANAGE']['userid']	= $row["id"];
					$sql = "insert into ".WWCMSLOGTABLE."(username,op,active,ip) values('$name','登录成功','$active','$ip')";
					$this->db->query($sql);
					Header("Location: ".ATHENA_SCRIPT_INDEX);
					exit;
				}
				else
				{
					$sql = "insert into ".WWCMSLOGTABLE."(username,op,active,ip) values('$name','密码错误，登录失败','$active','$ip')";
					$this->db->query($sql);
					$this->halt("登陆密码错误！","");
				}
			}
			else
			{
				$sql = "insert into ".WWCMSLOGTABLE."(username,op,active,ip) values('$name','用户名不存在，登录失败','$active','$ip')";
				$this->db->query($sql);
				$this->halt("用户名不存在！","");
			}
		}
		else
			$this->halt("查询用户表失败！","");
	}
}
?>